# Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.

import json
import subprocess

def get_config():
    with open("/root/builder/qtsm-sdk-c/samples/src/config.json") as f:
        Config = json.load(f)
        IAM = Config['IAM']
        AK = IAM['AK']
        SK = IAM['SK']
        KeyId = IAM['KeyId']
        ProjectId = IAM['ProjectId']
        allProjectId = "/v1.0/" + ProjectId + "/kms/"
        FileName = Config['FileName']
        Ciphertext = FileName['Ciphertext']
        Plaintext = FileName['Plaintext']
        OBSBucket = FileName['OBSBucket']
        Endpoint = Config['Endpoint']
        OBSEndpoint = Endpoint['OBSEndpoint']
        KMSEndpoint = Endpoint['KMSEndpoint']
        VsockSetting = Config['VsockSetting']
        VsockPort = VsockSetting['VsockPort']
        return [AK, SK, VsockPort, Ciphertext, Plaintext, OBSBucket, KeyId, KMSEndpoint, OBSEndpoint, allProjectId]

res = get_config()
command="/root/builder/qtsm-sdk-c/samples/enclave_demo_bin -a {0} -s {1} -p {2} -c {3} -l {4} -b {5} -k {6} -m {7} -o {8} -j {9}"
        .format(res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7], res[8], res[9])
subprocess.call(command, shell=True)
